package com.woniuxy.ams.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.ams.entity.AssessStandard;
import com.woniuxy.ams.entity.PageRequest;
import com.woniuxy.ams.entity.ResultEntity;
import com.woniuxy.ams.service.AssessStandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author Zjp
 */
@RestController
@RequestMapping("/Standard")
public class AssessStandardController {
    @Autowired(required = false)
    AssessStandardService assessStandardService;


    /**
     * 查询所有
     * */
    @RequestMapping("/findAllAssessStandard")
    public ResultEntity<?> findAllAssessStandard(@RequestBody PageRequest<AssessStandard> pageRequest) {
        PageHelper.startPage(pageRequest.getCurrentPage(), pageRequest.getLimit());
        AssessStandard data = pageRequest.getData();
        List<AssessStandard> assessStandards = assessStandardService.findAllAssessStandard(data);
        System.out.println(assessStandards);

        PageInfo<AssessStandard> objectPageInfo = new PageInfo<>(assessStandards);
        if (assessStandards.size() != 0) {
            return new ResultEntity<>(200, "查询成功", objectPageInfo);
        }else {
            return new ResultEntity<>(200, "查询失败,没有数据", objectPageInfo);
        }
    }
    /**
     * 查询所有(无分页供item使用)
     * */
    @RequestMapping("/findAll")
    public ResultEntity<?> findAll() {
        List<AssessStandard> assessStandards = assessStandardService.findAll();
        if (assessStandards.size() != 0) {
            return new ResultEntity<>(200, "查询成功", assessStandards);
        }else {
            return new ResultEntity<>(200, "查询失败,没有数据", assessStandards);
        }
    }

    /**
     * 添加assessType
     * */

    @RequestMapping("/addAssessStandard")
    public ResultEntity<AssessStandard> addAssessStandard(@RequestBody AssessStandard assessStandard) {
        System.out.println(assessStandard);
        boolean b = assessStandardService.addAssessStandard(assessStandard);

        if (b) {
            return new ResultEntity<>(200, "添加成功", null);
        } else {
            return new ResultEntity<>(500, "添加失败", null);
        }
    }


    /**
     * 删除assessType
     * */

    @RequestMapping("/deleteAssessStandard")
    public ResultEntity<AssessStandard> deleteAssessStandard(@RequestBody AssessStandard assessStandard) {
        boolean b = assessStandardService.deleteAssessStandard(assessStandard);

        if (b) {
            return new ResultEntity<>(200, "删除成功", null);
        } else {
            return new ResultEntity<>(500, "删除失败", null);
        }
    }


    /**
     * 修改assessType
     * */

    @RequestMapping("/updateAssessStandard")
    public ResultEntity<AssessStandard> updateAssessStandard(@RequestBody AssessStandard assessStandard) {
        boolean b = assessStandardService.updateAssessStandard(assessStandard);

        if (b) {
            return new ResultEntity<>(200, "修改成功", null);
        } else {
            return new ResultEntity<>(500, "修改失败", null);
        }
    }

    /**
     * 根据name查找指标
     * @param assessStandard
     * @return
     */
    @RequestMapping("/findByName")
    public ResultEntity<List<AssessStandard>> findByAssessmentStandardName(@RequestBody AssessStandard assessStandard) {
        List<AssessStandard> assessStandards = assessStandardService.findByAssessmentStandardName(assessStandard);
        if (assessStandards != null && assessStandards.size()!=0) {
            return new ResultEntity<>(200, "查询成功", assessStandards);
        }else {
            return new ResultEntity<>(500, "查询失败,没有此数据", null);
        }
    }

    /**
     * 根据id查找指标
     * @param assessStandard
     * @return
     */
    @RequestMapping("/findById")
    public ResultEntity<List<AssessStandard>> findById(@RequestBody AssessStandard assessStandard) {
        List<AssessStandard> assessStandards = assessStandardService.findById(assessStandard);
        if (assessStandards != null  && assessStandards.size()!=0) {
            return new ResultEntity<>(200, "查询成功", assessStandards);
        }else {
            return new ResultEntity<>(500, "查询失败,没有此数据", null);
        }
    }
    @RequestMapping("/findTheassessmentNameByName")
    public int[] findTheassessmentNameByName(@RequestBody AssessStandard assessStandard) {
        int arr[] = assessStandardService.findTheassessmentNameByName(assessStandard);
        return arr;
    }
    @RequestMapping("/find")
    public ResultEntity<?> find(String name,String assessmentTypes) {
        System.out.println(name+".............."+assessmentTypes);
        AssessStandard assessStandards = assessStandardService.find(name,assessmentTypes);
        if (assessStandards != null) {
            return new ResultEntity<>(200, "查询成功", assessStandards);
        }else {
            return new ResultEntity<>(200, "查询失败,没有数据", assessStandards);
        }
    }


    public int findIdByName(String name) {
       int id = assessStandardService.findIdByName(name);
       return id;
    }
}
